<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var x = 5

        var obj;

        function test2(){

            console.log(this.x)//5

        }

        obj = {

            x : 2,

            f(){
                var that = this
                function demo(){
                    console.log(this.x)//5
                    console.log(that.x)//2
                }
                demo()
            }
        }

        window.obj.f()
        test2()
    </script>
</head>
<body>
    
</body>
</html>